import http from "./http/http";

// headers 可选参数,正常的headers值   responseType 可选参数,  timeout  可选参数，设置当前接口的请求的超时时间 默认时间 40000
// url 求情地址  method 请求方式  proxyPrefix  请求代理标记，当有多个时可以设置,默认值 p1：'/api'  desc 接口的参数说明
// '获取列表': {
// 	url: "/vue-admin-template/table/list",
// 	method: "get",
// 	// proxyPrefix: "p1"
// },
// '获取用户信息': {
// 	url: "/vue-admin-template/user/info",
// 	method: "get",
// 	proxyPrefix: "p2",
// 	headers: {},
// 	responseType: "",
// 	timeout: 10000
// },
// http://172.16.9.27:8080/fssc/api/syncData/getBudgetInfo
const interfaceNameObj = {
	获取用户列表: {
		url: "/api/oa/get/userList",
		method: "get",
		desc: '[{phone:"手机号",password:"密码",type:"登录方式：0-密码登录"},{phone:"手机号",code:"验证码",type:"登录方式：1-验证码登录"},{phone:"手机号",code:"验证码",type:"登录方式：2-微信登录"}] ',
	},
	登录: {
		url: "/api/oa/login",
		method: "post",
	},
	获取年度预算: {
		url: "/sk/fssc/api/syncData/getBudgetInfo",
		method: "post",
	},

	用户登录: {
		url: "/vue-admin-template/user/login",
		method: "post",
	},
	获取用户信息: {
		url: "/vue-admin-template/user/info",
		method: "get",
	},
	退出登录: {
		url: "/vue-admin-template/user/logout",
		method: "post",
	},
	获取测试表数据: {
		url: "/vue-admin-template/table/list",
		method: "get",
	},
}

var Vue = null;
const API = {
  async API_getDataForDB(interfaceName, data, ...args) {
    const urlData = interfaceNameObj[interfaceName];
    if (!urlData || urlData.url === "") {
      return { mess: "不存在此接口，请检查后再调用" };
    }
    return await http[urlData["method"]](urlData.url, data, ...args);
  },
};

class HttpHelp {
  static install(vue, option) {
    Vue = vue;
    let that = this;
    Vue.mixin({
      beforeCreate() {
        window.$API_ = API;
        window.$interfaceName_ = interfaceNameObj;
        Vue.prototype.$API_ = API;
      },
    });
  }
}
export default HttpHelp;
